package com.itheima.info.system.manager.dao;

import com.itheima.info.system.manager.domain.Teacher;

import java.util.ArrayList;

public class TeacherDao implements IBaseTeacherDao {
    private ArrayList<Teacher> teachers = new ArrayList<>();

    @Override
    public void add(Teacher teacher) {
        teachers.add(teacher);
    }

    @Override
    public void delete(String sid) {
        int index = getIndexBySid(sid);
        teachers.remove(index);
    }

    @Override
    public void updata(String sid, Teacher teacher) {
        int index = getIndexBySid(sid);
        teachers.set(index, teacher);
    }

    @Override
    public ArrayList<Teacher> findAll() {
        return teachers;
    }

    @Override
    public int getIndexBySid(String sid) {
        int index = -1;
        for (int i = 0; i < teachers.size(); i++) {
            if (sid.equals(teachers.get(i).getSid())) {
                index = i;
            }
        }
        return index;
    }
}
